/*
 * libroxsd - a portable, lightweight XSD validation library
 * Copyright (C) 2012  Emmanuel Deloget
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

#include <stdlib.h>
#include "roxsd-list.h"

list_t *__list_pushback(list_t *head, list_t *node)
{
	if (!node)
		return head;

	list_t *current = head;
	list_t *prev = NULL;

	while (current) {
		prev = current;
		current = __list_next(current);
	}

	node->prev = prev;
	node->next = NULL;
	if (prev) {
		prev->next = node;
	} else {
		head = node;
	}

	return head;
}

list_t *__list_pushfront(list_t *head, list_t *node)
{
	if (!node)
		return head;

	node->next = head;
	if (head) {
		head->prev = node;
	}
	return node;
}

